/* component */
import LogisticsDialog from '@src/component/form/components/FormLogistics/LogisticsDialog';
/* util */
import fastCall from '@src/component/util/fastCall.ts'
/* vue */
import Vue from 'vue'

import { useNewVue } from '@hooks/useNewVue'
const { createVue } = useNewVue();

export function initLogisticsNoDialog(options = {}) {
  
  let visible = Boolean(options.visible)
  let info = options.info || {}
  
  let mode = options.mode || ''
  let bizId = options.bizId || ''
  
  let body = document.body;
  let mountEl = options.mountEl instanceof HTMLElement ? options.mountEl : body
  let ele = document.createElement('div');
  
  mountEl.appendChild(ele);
  
  return new Promise((resolve, reject) => {
    createVue({
      el: ele,
      data() {
        return {
          visible
        }
      },
      mounted() {
        this.$refs.LogisticsDialogComponent.open()
      },
      render() {
        return (
          <logistics-dialog
            ref="LogisticsDialogComponent"
            visible={this.visible}
            mode={mode}
            bizId={bizId}
            info={info}
            onClose={() => {
              this.visible = false
            }}
          >
          </logistics-dialog>
        )
      },
      components: {
        [LogisticsDialog.name]: LogisticsDialog
      }
    })
  })
}

const component = {
  install(Vue) {
    Vue.component(LogisticsDialog.name, LogisticsDialog)
    // 注册快速调用方法
    fastCall(Vue, 'biz', { initLogisticsNoDialog })
  },
  namespace: 'biz',
  props: { initLogisticsNoDialog }
}

export default component
